package org.clipjoint.service.impl;

import org.clipjoint.dao.KeyWordAdminDao;
import org.clipjoint.dao.impl.KeyWordAdminDaoImpl;
import org.clipjoint.entity.KeyWord;
import org.clipjoint.entity.dto.KeyWordDto;
import org.clipjoint.service.keywordAdminService;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class keywordAdminServiceImpl implements keywordAdminService {

    KeyWordAdminDao keyWordAdminDao = new KeyWordAdminDaoImpl();

    @Override
    public List<KeyWordDto> list(KeyWordDto keywordDto) throws SQLException {
        return keyWordAdminDao.selectAll(keywordDto);
    }

    @Override
    public Long count(KeyWordDto build) throws SQLException {
        return keyWordAdminDao.selectCount(build);
    }

    @Override
    public int deleteAll(List<Long> ids) {
        int result = 0;
        for (Long id : ids) {
            try {
                result += keyWordAdminDao.deleteById(id);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return result;
    }

    @Override
    public int del(Long id) throws SQLException {
        return keyWordAdminDao.deleteById(id);
    }

    @Override
    public int add(KeyWord build) throws SQLException {

        build.setCreate_time(new Date());
        return keyWordAdminDao.insert(build);
    }
}
